import java.util.Arrays;

/*
 * @lc app=leetcode.cn id=322 lang=java
 *
 * [322] 零钱兑换
 */

// @lc code=start
class Solution {
    public int coinChange(int[] coins, int amount) {
        int[] dp = new int[amount+1];
        for (int i = 0; i < dp.length; i++) {
            dp[i] = amount+1; 
        }
        dp[0] = 0;
        for (int i = 0; i < coins.length; i++) { //硬币 从0开始
            for (int j = 0; j <= amount; j++) { // 硬币的金额，从1开始
                if(j - coins[i] >= 0){
                    dp[j] = Math.min(dp[j], dp[j-coins[i]]+1);
                }
            }
        }
        System.out.println(Arrays.toString(dp));
        return dp[amount] > amount ? -1 : dp[amount];
    }
}
// @lc code=end

